package com.qqtem.grupo14;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;

public class LocalContentProvider extends ContentProvider {
	public static final Uri CONTENT_URI = Uri.parse("content://com.qqtem.grupo14.localcontentprovider");
	public static final String PROVIDER_NAME = "com.qqtem.grupo14.localcontentprovider";
	private DatabaseAdapter db = null;
	
	public void init(){
		
	}
	
	@Override
	public boolean onCreate() {
		db = DatabaseAdapter.getSingletonInstance();
		db.open();
		return false;
	}

	@Override
	public int delete(Uri uri, String selection, String[] selectionArgs) {
		return 0;
	}

	@Override
	public String getType(Uri uri) {
		return null;
	}

	@Override
	public Uri insert(Uri uri, ContentValues values) {
		long id = db.createPlace(values.getAsString(DatabaseAdapter.NAME), values.getAsString(DatabaseAdapter.DESCRIPTION), values.getAsString(DatabaseAdapter.TAGS), values.getAsString(DatabaseAdapter.TYPE), values.getAsString(DatabaseAdapter.PHOTO), values.getAsInteger(DatabaseAdapter.LAT), values.getAsInteger(DatabaseAdapter.LONG), values.getAsInteger(DatabaseAdapter.CREATEDBY));
		return Uri.parse(CONTENT_URI + "/" + id);
	}

	@Override
	public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
		Cursor c = null;
		if(selection == null){
			c = db.fetchAllPlaces();
		} else {
			//c = db.fetchPlace(Integer.getInteger(selection));
		}
		return c;
	}

	@Override
	public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
		return 0;
	}

}
